package cn.tx.controller;

import cn.tx.constant.MessageConstant;
import cn.tx.entity.Result;
import cn.tx.pojo.User;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/9/10 17:10
 * @Email: 1164763541@qq.com
 */
@RestController
@RequestMapping("user")
public class UserController {
    @RequestMapping("getUsername.do")
    public Result getUsername() {
        try {
            org.springframework.security.core.userdetails.User principal  = (org.springframework.security.core.userdetails.User)
                    SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            return new Result(true,MessageConstant.GET_USERNAME_SUCCESS,principal.getUsername());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_USERNAME_FAIL);
        }
    }

    //修改密码
    @RequestMapping("changPassword.do")
    public Result forgetPassword(User user) {
        System.out.println(user);
        return null;
    }

}
